﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;


namespace WebControlApp
{
    public partial class Main : Form, Iview
    {
        UI.Presenter m_Presenter;
        

        public Main()
        {
            InitializeComponent();
            m_Presenter = new UI.Presenter(this);
        }

        public Uri VideoAddress
        {
            get{return webBrowser1.Url;}
            set{webBrowser1.Url=value;}
        }
        public string RawSensorData
        {
            get {return textBox2.Text;}
            set{textBox2.Text=value;}
        }
        public string LogView
        {
            get { return textBox1.Text;}
            set {textBox1.Text=value;}
        }
        public double LeftIRSensor
        {
            get { return trackBar1.Value; }
            set
            {
                trackBar1.Value = (int)value;
                label17.Text = ((int)value).ToString() + "in";
            }
        }
        public double RightIRSensor
        {
            get { return trackBar2.Value; }
            set
            {
                trackBar2.Value = (int)value;
                label18.Text = ((int)value).ToString() + "in";
            }
        }
        public double UltraSonicSensor
        {
            get { return trackBar3.Value ;}
            set 
            { 
            trackBar3.Value=(int)value;
            label16.Text = ((int)value).ToString() + "in";
            }
        }
        public string LeftMotorCurrent
        {
            get {return label11.Text;}
            set { label11.Text=value;}
        }
        public string RightMotorCurrent
        {
            get { return label12.Text; }
            set { label12.Text = value; }
        }
        public string LeftEncoder
        {
            get { return label10.Text; }
            set { label10.Text = value; }
        }
        public string RightEncoder
        {
            get { return label13.Text; }
            set { label13.Text = value; }
        }
        public string MaxSpeed
        {
            get { return label7.Text; }
            set
            {
                label7.Text = value;
            }
        }
        public string TimerLength
        {
            get { return label4.Text; }
            set
            {
                label4.Text = value;
            }
        }
        public bool SensorOverride
        {
            get {return checkBox1.Checked ;}
            set {checkBox1.Checked=value; }
        }
        public bool Calibrate
        {
            get { return checkBox3.Checked; }
            set { checkBox3.Checked = value; }
        }
        public bool AutoBrake
        {
            get { return checkBox2.Checked; }
            set { checkBox2.Checked = value; }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            //network
            //FIX
        }


        private void connect_Click(object sender, EventArgs e)
        {
            m_Presenter.Connect();
        }

        private void button14_Click(object sender, EventArgs e)
        {
            //disconnect
            m_Presenter.Dissconnect();
        }

        private void Main_KeyDown(object sender, KeyEventArgs e)
        {
            m_Presenter.Keydown(e.KeyData);
        }

        private void Main_KeyUp(object sender, KeyEventArgs e)
        {
            //Stop
            m_Presenter.Stop();
        }

        private void button8_Click_1(object sender, EventArgs e)
        {
            //Fix            
            webBrowser1.Refresh();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //forward
            m_Presenter.forward();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //Reverse
            m_Presenter.reverse();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Piviot Left
            m_Presenter.PiviotLeft();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //Piviot Right
            m_Presenter.PiviotRight();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //stop
            m_Presenter.Stop();
        }

        private void trackBar4_Scroll(object sender, EventArgs e)
        {
            m_Presenter.ChangeSyncTime(trackBar4.Value);
        }

        private void trackBar5_Scroll(object sender, EventArgs e)
        {
            m_Presenter.ChangedSpeed(trackBar5.Value);
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            //AutoBrake
            m_Presenter.AutoBrake();
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
           //Calibrate
            m_Presenter.Calibrate();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            //sensor override
            m_Presenter.SensorOverRide();
        }
   }
}
